// pages/about/index.js
var util = require('../../utils/util.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    mobile: "",
    phone: "",
    fax: "",
    qq: "",
    ww:"",
    address:"",
    location:"",
    latitudes: "",
    longitudes: "",
    name:"",
    isAiweapp:true
  },

  tapchat:function(){
    if (app.globalData.userStaff) {
      // var name = encodeURIComponent(app.globalData.userStaff.Name);
      // var seltoid = app.globalData.userStaff.Uid
      // wx.navigateTo({
      //   url: '/pages/weijieke/Business/Business?seltoid=' + seltoid + '&name=' + name,
      // })
      util.tapChat(app.globalData.userStaff);
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    util.isAiWeApp(app, function (data) {
      that.setData({ isAiweapp: data })
    });
    that.about();
  },

  callphone:function(e){
    var that = this;
    wx.makePhoneCall({
      phoneNumber: e.currentTarget.dataset.phone,
      success: function (res) {
        console.log(res);
      },
      fail: function (err) {
        console.log(err);
      },
      complete: function (res) {
        console.log(res);
      },
    })
  },

  callmobile: function (e) {
    var that = this;
    wx.makePhoneCall({
      phoneNumber: e.currentTarget.dataset.mobile,
      success: function (res) {
        console.log(res);
      },
      fail: function (err) {
        console.log(err);
      },
      complete: function (res) {
        console.log(res);
      },
    })
  },

  toMap:function(){
   wx.navigateTo({
     url: '/pages/map/index?location=' + this.data.location,
   })
  },
  toLiuyan: function(){
    wx.navigateTo({
      url: '/pages/yuyue/index',
    })
  },

  //客服
  about:function(){
    var that = this;
    wx.request({
      url: app.globalData.host + '/api/store/GetInfo?id=' + app.globalData.storeId,
      success: function (res) {
        var Mobile = res.data.Data.Mobile
        var Phone = res.data.Data.Phone
        var Fax = res.data.Data.Fax
        var QQ = res.data.Data.QQ
        var WW = res.data.Data.WW
        var name = res.data.Data.Name
        var Address = res.data.Data.Address 
        var Location = res.data.Data.Location
        var latitudes = Location.substring(0, Location.indexOf(','));//	纬度
        var locations2 = Location.substring(Location.indexOf(','));
        var longitudes = locations2.slice(1)//经度
        latitudes = parseFloat(latitudes)
        longitudes = parseFloat(longitudes)
        that.setData({
          mobile: Mobile,
          phone: Phone,
          fax: Fax,
          qq: QQ,
          ww: WW,
          name: name,
          address: Address,
          latitudes: latitudes,
          longitudes: longitudes
        })
      }
    })
  },

  //地图导航
  openMap: function () {
    var that = this;
    wx.showModal({
      title: '提示',
      content: '是否打开地图导航',
      success: function (res) {
        if (res.confirm) {
          wx.getLocation({
            type: 'gcj02', //返回可以用于wx.openLocation的经纬度
            success: function (res) {
              var latitude = res.latitude
              var longitude = res.longitude
              wx.openLocation({
                latitude: that.data.latitudes,
                longitude: that.data.longitudes,
                scale: 28,
                name: "点击右边打开地图导航",
                address: that.data.address
              })
            }
          })
        } else if (res.cancel) {
         
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  }
})